<?php
require_once("inc.public.php");
require_once(M_ROOT."/functions/downline/downline_function.php");
require_once(M_ROOT."/functions/comm/comm_function.php");

$r=mysql_query("SELECT * FROM gg_member_ewallet_record WHERE cdate like '2010-06-03 16:44%' and descr like '%from bulk matching commission received.' ORDER BY gg_member_ewallet_record.cdate,id");
while ($legder = mysql_fetch_assoc($r)) {
	if($legder['type']=='credit'){		
		mysql_query("update gg_users set ewallet=ewallet-".$legder['amount']." where id=".$legder['uid']);
		mysql_query("delete from gg_member_ewallet_record where id=".$legder['id']);
		mysql_query("update gg_member_ewallet_record set bal=bal-".$legder['amount']." where cdate>='2010-06-03 16:44:36' and uid=".$legder['uid']);		
	}
	
	if($legder['type']=='debit'){		
		mysql_query("update gg_users set ewallet=ewallet+".$legder['amount']." where id=".$legder['uid']);
		mysql_query("delete from gg_member_ewallet_record where id=".$legder['id']);
		mysql_query("update gg_member_ewallet_record set bal=bal+".$legder['amount']." where cdate>='2010-06-03 16:44:36' and uid=".$legder['uid']);
		
		$maintain = mysql_fetch_assoc(mysql_query("select * from gg_member_maintain where uid=".$legder['uid']." and amount=".$legder['amount']." and cdate>='2010-06-03 16:44:36'"));
		if($maintain){
			mysql_query("update gg_users set swallet=swallet-".$legder['amount']." where id=".$legder['uid']);
			mysql_query("delete from gg_member_maintain where id=".$maintain['id']);
			$maintain2 = mysql_fetch_assoc(mysql_query("select * from gg_member_swallet_record where uid=".$legder['uid']." and amount=".$legder['amount']." and cdate>='2010-06-03 16:44:36'"));
			mysql_query("delete from gg_member_swallet_record where id=".$maintain2['id']);
			mysql_query("update gg_member_swallet_record set bal=bal-".$legder['amount']." where cdate>='2010-06-03 16:44:36' and uid=".$legder['uid']);	
		}
		
		$maintain = mysql_fetch_assoc(mysql_query("select * from gg_member_mwallet_record where uid=".$legder['uid']." and amount=".$legder['amount']." and cdate>='2010-06-03 16:44:36'"));
		if($maintain){
			mysql_query("update gg_users set mwallet=mwallet-".$legder['amount']." where id=".$legder['uid']);
			mysql_query("delete from gg_member_mwallet_record where id=".$maintain['id']);
			mysql_query("update gg_member_mwallet_record set bal=bal-".$legder['amount']." where cdate>='2010-06-03 16:44:36' and uid=".$legder['uid']);						
		}
	}	
}

print_r('finish');
exit;
?>